// 1. 定义路由组件.
// 也可以从其他文件导入
// const Home = { template: '<div>Home</div>' }
import Home from '../views/home.vue'

// 2. 定义一些路由
// 每个路由都需要映射到一个组件。
// 我们后面再讨论嵌套路由。
export const routes = [
    {path: '/', component: Home},
    {
        path: '/base',
        component: () => import('../views/base.js'),
        redirect: '/base/base',
        meta: {
            title: '介绍'
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/base/base.vue')
            },
            {
                path: 'lib',
                meta: {
                    title: '库'
                },
                component: () => import('../views/base/lib.vue')
            },
            {
                path: 'develop',
                meta: {
                    title: '交互'
                },
                component: () => import('../views/base/develop.vue')
            },
            {
                path: 'formHelper',
                meta: {
                    title: 'formHelper',
                    hide: true
                },
                component: () => import('../views/base/formHelper.vue')
            },
        ]
    },

    // {
    //     path: '/pages',
    //     component: () => import('../views/pages.js'),
    //     redirect: '/pages/base',
    //     meta: {},
    //     children: [
    //         {
    //             path: 'base',
    //             meta: {
    //                 title: '页面'
    //             },
    //             component: () => import('../views/pages/base')
    //         },
    //         {
    //             path: 'table',
    //             meta: {
    //                 title: '表格关系组件'
    //             },
    //             component: () => import('../views/pages/table')
    //         },
    //         {
    //             path: 'my',
    //             meta: {
    //                 title: '我的',
    //                 hide: true
    //             },
    //             component: () => import('../views/pages/my')
    //         },
    //         {
    //             path: 'case',
    //             meta: {
    //                 title: '详情',
    //             },
    //             component: () => import('../views/pages/case')
    //         },
    //         {
    //             path: 'lesson',
    //             meta: {
    //                 title: '课程1',
    //             },
    //             component: () => import('../views/pages/lesson')
    //         },
    //         {
    //             path: 'lesson2',
    //             meta: {
    //                 title: '课程2',
    //             },
    //             component: () => import('../views/pages/lesson2')
    //         },
    //         {
    //             path: 'lesson3',
    //             meta: {
    //                 title: '课程3',
    //             },
    //             component: () => import('../views/pages/lesson3')
    //         },
    //         {
    //             path: 'play',
    //             meta: {
    //                 title: '播放页面',
    //             },
    //             component: () => import('../views/pages/play')
    //         },
    //         // {
    //         //     path: 'design',
    //         //     meta: {
    //         //         title: '页面'
    //         //     },
    //         //     component: () => import('../views/pages/design')
    //         // }
    //     ]
    // },
    {
        path: '/im',
        component: () => import('../views/im.js'),
        redirect: '/im/base',
        meta: {
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: 'DOC'
                },
                component: () => import('../views/im/base.vue')
            },
            {
                path: 'cascader',
                meta: {
                    title: '分享'
                },
                component: () => import('../views/im/cascader.vue')
            },
        ]
    },
    {
        path: '/layout',
        component: () => import('../views/layout.js'),
        redirect: '/layout/base',
        meta: {
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: 'TABLE'
                },
                component: () => import('../views/layout/base.vue')
            },
        ]
    },
    {
        path: '/grid',
        component: () => import('../views/grid.js'),
        redirect: '/grid/base',
        meta: {
            title: '布局组件'
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: 'row'
                },
                component: () => import('../views/grid/base.vue')
            },
            {
                path: 'row',
                meta: {
                    title: '格栅系统'
                },
                component: () => import('../views/grid/row.vue')
            },
            {
                path: 'wall',
                meta: {
                    title: '瀑布流'
                },
                component: () => import('../views/grid/wall.vue')
            },
            {
                path: 'excel',
                meta: {
                    title: 'excel',
                },
                component: () => import('../views/grid/excel.vue')
            },
        ]
    },
    {
        path: '/table',
        component: () => import('../views/table.js'),
        redirect: '/table/base',
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础表格'
                },
                component: () => import('../views/table/base.vue')
            },
            {
                path: 'pagination',
                meta: {
                    title: '表格分页'
                },
                component: () => import('../views/table/pagination.vue')
            },
            {
                path: 'button',
                meta: {
                    title: '表格按钮'
                },
                component: () => import('../views/table/button.vue')
            },
            {
                path: 'row-edit',
                meta: {
                    title: '表格行编辑'
                },
                component: () => import('../views/table/row-edit.vue')
            },
            {
                path: 'slot-button',
                meta: {
                    title: '按钮插槽'
                },
                component: () => import('../views/table/button-slot.vue')
            },
            {
                path: 'column-slot',
                meta: {
                    title: '表格行插槽'
                },
                component: () => import('../views/table/column-slot.vue')
            },
            {
                path: 'header',
                meta: {
                    title: '表格头'
                },
                component: () => import('../views/table/header.vue')
            },
            {
                path: 'tree',
                meta: {
                    title: '表格树'
                },
                component: () => import('../views/table/tree.vue')
            },
            {
                path: 'radio',
                meta: {
                    title: '单选',
                    hide: true
                },
                component: () => import('../views/table/radio.vue')
            },
        ]
    },
    {
        path: '/tree_table',
        component: () => import('../views/tree_table.js'),
        redirect: '/tree_table/base',
        meta: {
            title: '表格ext'
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '多选'
                },
                component: () => import('../views/tree_table/base.vue')
            },
        ]
    },
    {
        path: '/tree',
        component: () => import('../views/tree.js'),
        redirect: '/tree/base',
        meta: {
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/tree/base.vue')
            },
            {
                path: 'directory',
                meta: {
                    title: '选择'
                },
                component: () => import('../views/tree/directory.vue')
            },
        ]
    },
    {
        path: '/menu',
        component: () => import('../views/menu.js'),
        redirect: '/menu/base',
        meta: {
            title: '菜单'
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: 'base'
                },
                component: () => import('../views/menu/base.vue')
            },
            {
                path: 'right',
                meta: {
                    title: '右键'
                },
                component: () => import('../views/menu/right.vue')
            },
        ]
    },
    {
        path: '/space',
        component: () => import('../views/space.js'),
        redirect: '/space/base',
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/space/base.vue')
            },
        ]
    },
    {
        path: '/icon',
        component: () => import('../views/icon.js'),
        redirect: '/icon/base',
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/icon/base.vue')
            },
        ]
    },
    {
        path: '/tabs',
        component: () => import('../views/tabs.js'),
        redirect: '/tabs/base',
        meta: {
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/tabs/base.vue')
            },
        ]
    },
    {
        path: '/form',
        component: () => import('../views/form.js'),
        redirect: '/form/base',
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/form/base.vue')
            },
            {
                path: 'custom',
                meta: {
                    title: '自定义'
                },
                component: () => import('../views/form/custom.vue')
            },
            {
                path: 'arr',
                meta: {
                    title: '构建'
                },
                component: () => import('../views/form/arr.vue')
            },
            {
                path: 'fox',
                meta: {
                    title: '复杂结构'
                },
                component: () => import('../views/form/fox.vue')
            },
            {
                path: 'validate',
                meta: {
                    title: '验证'
                },
                component: () => import('../views/form/validate.vue')
            },
            {
                path: 'event',
                meta: {
                    title: '事件'
                },
                component: () => import('../views/form/event.vue')
            },
            {
                path: 'layout',
                meta: {
                    title: '布局',
                },
                component: () => import('../views/form/layout.vue')
            },
            {
                path: 'global',
                meta: {
                    title: '全局配置',
                },
                component: () => import('../views/form/global.vue')
            },
            // {
            //     path: 'async',
            //     meta: {
            //         title: '异步',
            //     },
            //     component: () => import('../views/form/async.vue')
            // },
            {
                path: 'control',
                meta: {
                    title: '全局配置',
                    hide: true
                },
                component: () => import('../views/form/control.vue')
            },
        ]
    },
    {
        path: '/datatable',
        component: () => import('../views/datatable.js'),
        redirect: '/datatable/base',
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/datatable/base.vue')
            },
            // {
            //     path: 'crud',
            //     meta: {
            //         title: '增删改查'
            //     },
            //     component: () => import('../views/datatable/crud.vue')
            // },
            {
                path: 'infinite',
                meta: {
                    title: '无限滚动',
                    hide: true
                },
                component: () => import('../views/datatable/infinite.vue')
            },
            {
                path: 'static',
                meta: {
                    title: '静态',
                    hide: true
                },
                component: () => import('../views/datatable/static.vue')
            },
            {
                path: 'single',
                meta: {
                    title: '单选',
                    hide: true
                },
                component: () => import('../views/datatable/single.vue')
            },
            {
                path: 'select',
                meta: {
                    title: '选择',
                    hide: true
                },
                component: () => import('../views/datatable/select.vue')
            },
            {
                path: 'tree',
                meta: {
                    title: '树table'
                },
                component: () => import('../views/datatable/tree.vue')
            },
        ]
    },
    {
        path: '/chart',
        component: () => import('../views/chart.js'),
        redirect: '/chart/base',
        meta: {
            // hide: true
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/chart/base.vue')
            },
            {
                path: 'devlop',
                meta: {
                    title: '开发'
                },
                component: () => import('../views/chart/devlop.vue')
            },
            // {
            //     path: 'line',
            //     meta: {
            //         title: '折线图'
            //     },
            //     component: () => import('../views/chart/line.vue')
            // },
            // {
            //     path: 'bar',
            //     meta: {
            //         title: '柱状图'
            //     },
            //     component: () => import('../views/chart/bar.vue')
            // },
            // {
            //     path: 'pie',
            //     meta: {
            //         title: '饼图'
            //     },
            //     component: () => import('../views/chart/pie.vue')
            // },
            {
                path: 'china',
                meta: {
                    title: '中国地图',
                },
                component: () => import('../views/chart/china.vue')
            },
            {
                path: 'jiangsu',
                meta: {
                    title: '江苏地图',
                },
                component: () => import('../views/chart/jiangsu.vue')
            },
            // {
            //   path: 'linyi',
            //   meta: {
            //     title: '临沂地图',
            //     hide: true
            //   },
            //   component: () => import('../views/chart/linyi.vue')
            // },
            {
                path: 'suzhou',
                meta: {
                    title: '苏州地图',
                },
                component: () => import('../views/chart/suzhou.vue')
            },
        ]
    },
    // {
    //     path: '/drag',
    //     component: () => import('../views/drag.js'),
    //     redirect: '/drag/base',
    //     meta: {
    //     },
    //     children: [
    //         {
    //             path: 'base',
    //             meta: {
    //             },
    //             component: () => import('../views/drag/base')
    //         }
    //     ]
    // },
    {
        path: '/scroll',
        component: () => import('../views/scroll.js'),
        redirect: '/scroll/base',
        meta: {
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/scroll/base.vue')
            },
        ]
    },
    {
        path: '/tpl',
        component: () => import('../views/tpl.js'),
        redirect: '/tpl/base',
        meta: {
            hide: true
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/tpl/base.vue')
            },
        ]
    },
    {
        path: '/calendar',
        component: () => import('../views/calendar.js'),
        redirect: '/calendar/base',
        meta: {},
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/calendar/base.vue')
            },
        ]
    },
    {
        path: '/demo',
        component: () => import('../views/demo.js'),
        redirect: '/demo/base',
        meta: {
            hide: true
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/demo/base.vue')
            },
            {
                path: 'demo1',
                meta: {
                    title: '列表'
                },
                component: () => import('../views/demo/demo1.vue')
            },
            {
                path: 'demo2',
                meta: {
                    title: '表单'
                },
                component: () => import('../views/demo/demo2.vue')
            },
        ]
    },
    {
        path: '/zcard',
        component: () => import('../views/zcard.js'),
        redirect: '/zcard/base',
        meta: {},
        children: [
            {
                path: 'base',
                meta: {
                    title: '卡片'
                },
                component: () => import('../views/zcard/base.vue')
            },
            {
                path: 'layoutpanel',
                meta: {
                    title: '布局面板'
                },
                component: () => import('../views/zcard/layoutpanel.vue')
            },
        ]
    },
    {
        path: '/editor',
        component: () => import('../views/editor.js'),
        redirect: '/editor/base',
        meta: {},
        children: [
            {
                path: 'base',
                meta: {
                    title: '基础'
                },
                component: () => import('../views/editor/base.vue')
            },
            // {
            //   path: 'wang',
            //   meta: {
            //     title: 'wangEditor'
            //   },
            //   component: () => import('../views/editor/wang.vue')
            // },
        ]
    },
    // {
    //     path: '/zviewmode',
    //     component: () => import('../views/zviewmode.js'),
    //     redirect: '/zviewmode/base',
    //     meta: {},
    //     children: [
    //         {
    //             path: 'base',
    //             meta: {
    //                 title: '视图'
    //             },
    //             component: () => import('../views/zviewmode/base')
    //         }
    //     ]
    // },
    {
        path: '/description',
        component: () => import('../views/description.js'),
        redirect: '/description/base',
        meta: {
            // hide: true
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '描述'
                },
                component: () => import('../views/description/base')
            }
        ]
    },
    {
        path: '/plumb',
        component: () => import('../views/plumb.js'),
        redirect: '/plumb/base',
        meta: {
            hide: true
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '描述'
                },
                component: () => import('../views/plumb/base')
            }
        ]
    },
    {
        path: '/video',
        component: () => import('../views/video.js'),
        redirect: '/video/base',
        meta: {
            hide: true
        },
        children: [
            {
                path: 'base',
                meta: {
                },
                component: () => import('../views/video/base')
            }
        ]
    },
    {
        path: '/responsive',
        component: () => import('../views/responsive.js'),
        redirect: '/responsive/base',
        meta: {
            hide: true
        },
        children: [
            {
                path: 'base',
                meta: {
                },
                component: () => import('../views/responsive/base')
            }
        ]
    },
    // {
    //     path: '/comment',
    //     component: () => import('../views/comment.js'),
    //     redirect: '/comment/base',
    //     meta: {
    //     },
    //     children: [
    //         {
    //             path: 'base',
    //             meta: {
    //             },
    //             component: () => import('../views/comment/base')
    //         }
    //     ]
    // },
    {
        path: '/ellipsis',
        component: () => import('../views/ellipsis.js'),
        redirect: '/ellipsis/base',
        meta: {
        },
        children: [
            {
                path: 'base',
                meta: {
                },
                component: () => import('../views/ellipsis/base')
            }
        ]
    },
    {
        path: '/format',
        component: () => import('../views/format.js'),
        redirect: '/format/base',
        meta: {
        },
        children: [
            {
                path: 'base',
                meta: {
                    title: '数字'
                },
                component: () => import('../views/format/base')
            },
            {
                path: 'mask',
                meta: {
                    title: '规定'
                },
                component: () => import('../views/format/mask')
            },
            {
                path: 'screenshot',
                meta: {
                    title: '截图'
                },
                component: () => import('../views/format/screenshot')
            },
            {
                path: 'slider',
                meta: {
                    title: '多个',
                    hide: true
                },
                component: () => import('../views/format/slider')
            },
        ]
    },
]

/**
 * 获取route 定义
 * @param path
 */
export function getCurRouteDef({path = ''} = {}) {
    if (path) {
        let route = routes.find(v => v.path === path)
        return route
    }
}

export function getParRouteDef(route) {
    // console.log(route)
    let matched = route.matched ?? []
    if (matched.length > 1) {
        return getCurRouteDef(matched[matched.length - 2])
    }
    return null
}

